﻿namespace 代码性能测试
{
    internal class Program
    {
        static void Main(string[] args)
        {
            DateTime startDt = DateTime.Now;
            Calc10(1500000000);
            DateTime endDt = DateTime.Now;
            TimeSpan secondSpan = new TimeSpan(endDt.Ticks - startDt.Ticks);
            long mSec = (long)secondSpan.TotalMilliseconds;
            Console.WriteLine("mSec:{0}",mSec);
        }

        static long Calc1(long n)
        {
            long result = 1;
            for(long i = 0; i < n; i++)
            {
                result *= i;
            }
            return result;
        }

        static long Calc2(long n)
        {
            long result1 = 1;
            long result2 = 1;

            for (long i = 0; i < n; i+=2)
            {
                result1 *= i;
                result2 *= (i+1);
            }
            return result1 * result2 ;
        }

        static long Calc3(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;

            for (long i = 0; i < n; i += 3)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
            }
            return result1 * result2 * result3 ;
        }

        static long Calc4(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;

            for (long i = 0; i < n; i += 4)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
            }
            return result1 * result2 * result3 * result4 ;
        }

        static long Calc5(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;
            long result5 = 1;
            for (long i = 0; i < n; i += 5)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
                result5 *= (i + 4);
            }
            return result1 * result2 * result3 * result4 * result5;
        }

        static long Calc6(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;
            long result5 = 1;
            long result6 = 1;
            for (long i = 0; i < n; i += 6)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
                result5 *= (i + 4);
                result6 *= (i + 5);
            }
            return result1 * result2 * result3 * result4 * result5 * result6;
        }

        static long Calc7(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;
            long result5 = 1;
            long result6 = 1;
            long result7 = 1;
            for (long i = 0; i < n; i += 7)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
                result5 *= (i + 4);
                result6 *= (i + 5);
                result7 *= (i + 6);
            }
            return result1 * result2 * result3 * result4 * result5 * result6 * result7;
        }

        static long Calc8(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;
            long result5 = 1;
            long result6 = 1;
            long result7 = 1;
            long result8 = 1;
            for (long i = 0; i < n; i += 8)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
                result5 *= (i + 4);
                result6 *= (i + 5);
                result7 *= (i + 6);
                result8 *= (i + 7);
            }
            return result1 * result2 * result3 * result4 * result5 * result6 * result7 * result8;
        }

        static long Calc9(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;
            long result5 = 1;
            long result6 = 1;
            long result7 = 1;
            long result8 = 1;
            long result9 = 1;
            for (long i = 0; i < n; i += 9)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
                result5 *= (i + 4);
                result6 *= (i + 5);
                result7 *= (i + 6);
                result8 *= (i + 7);
                result9 *= (i + 8);
            }
            return result1 * result2 * result3 * result4 * result5 * result6 * result7 * result8 * result9;
        }

        static long Calc10(long n)
        {
            long result1 = 1;
            long result2 = 1;
            long result3 = 1;
            long result4 = 1;
            long result5 = 1;
            long result6 = 1;
            long result7 = 1;
            long result8 = 1;
            long result9 = 1;
            long result10 = 1;
            for (long i = 0; i < n; i += 10)
            {
                result1 *= i;
                result2 *= (i + 1);
                result3 *= (i + 2);
                result4 *= (i + 3);
                result5 *= (i + 4);
                result6 *= (i + 5);
                result7 *= (i + 6);
                result8 *= (i + 7);
                result9 *= (i + 8);
                result10 *= (i + 9);
            }
            return result1 * result2 * result3 * result4 * result5 * result6 * result7 * result8 * result9 * result10;
        }

    }
}